﻿using DevExpress.Mvvm;
using Microsoft.EntityFrameworkCore;
using OneStress.PropertyNodes;
using OneStress.ViewModels;
using orm.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OneStress
{
    internal class OrgnizationManager
    {
        public OrgnizationManager()
        {
           
            LoadOrgnizations();
        }

        public static OrgnizationManager Instance { get; private set; } = new OrgnizationManager();
        public List<OrgEntity> Orgnizations { get; private set; }
        public OrgEntity CurrentOrg { get; internal set; }

        public void LoadOrgnizations()
        {
            Orgnizations?.Clear();

            var dbContext = ServiceContainer.Default.GetService<IDisposable>("DBSerice") as OneSysDBContext;
            // project => site => well => wellbore
            Orgnizations = dbContext.Orgnization.Where(v => v.Type == 1)
             .Include(v => v.SubOrgs).ThenInclude(c => c.SubOrgs)
             .ThenInclude(c => c.SubOrgs)
             .Select(v => new OrgEntity()
             {
                 Root = v
             }).ToList();
        }
    }
}
